package calculatorController;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.StringTokenizer;

import javax.swing.JButton;

import calculatorModel.Mult;
import calculatorModel.Operation;
import calculatorView.CalculatorArea;

public class MultButton extends JButton {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Operation operator;
	private CalculatorArea area;

	public MultButton(Operation operator, CalculatorArea area) {
		super();
		this.operator = operator;
		this.area = area;
		this.setText("x");
		setMultButton();
	}

	private void setMultButton() {

		this.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				String espression = area.getArea().getText();

				StringTokenizer strtok = new StringTokenizer(espression, " ");
				int verifySeq = strtok.countTokens();

				if (verifySeq == 1) {

					area.getArea().append(" x ");
					operator.setOperator(new Mult());
				}
			}
		});

	}
}
